dojo.provide("msos.input_select");
dojo.require("msos.selection");
msos.input_select.input_get_str_end=function(_1){
var _2={start:0,end:0,pos_debug:"\nstart/end -> na"};
var _3="\nMethod: ";
if(_1.selectionStart){
_2.start=_1.selectionStart;
_2.end=_1.selectionEnd;
_3+="selectionStart-selectionEnd";
}else{
if(_1.createTextRange&&document.body.createTextRange){
var _4=0;
var _5=0;
var _6=0;
var _7=0;
var _8=0;
var _9=null;
_3+="moveStart-moveEnd IE";
if(document.selection){
_9=document.selection.createRange();
}
if(_9){
while(_9.moveStart("character",-1)!=0){
_4++;
}
while(_9.moveEnd("character",-1)!=0){
_5++;
}
}
_3+="\nDoc range: str - > "+_4+", end -> "+_5;
var _a=_1.createTextRange();
while(_a.moveEnd("character",-1)!=0){
_8++;
}
_3+="\nElm range: elm (real) end - > "+_8;
var _b=dojo.body().createTextRange();
_b.moveToElementText(_1);
while(_b.moveStart("character",-1)!=0){
_6++;
}
while(_b.moveEnd("character",-1)!=0){
_7++;
}
_3+="\nBody range: str - > "+_6+", end -> "+_7;
var _c=(_1.nodeName.toLowerCase()!="input")?true:false;
var _d=(_7-_8==_6)?true:false;
if((_4>0)&&_c&&_d){
_4-=_6;
}
if((_5>0)&&_c&&_d){
_5-=_6;
}
_2.start=_4;
_2.end=_5;
}
}
_3="\n\nGet str/end"+": str -> "+_2.start+", end -> "+_2.end+_3;
_2.pos_debug=_3;
_2.start=_2.start>0?_2.start:0;
_2.end=_2.end>0?_2.end:0;
_2.end=(_2.end<_2.start)?_2.start:_2.end;
return _2;
};
msos.input_select.text_ins_del=function(_e){
var _f=this;
this.input=_e;
this.cursor={};
this.debug="";
this.input_set_focus=function(){
_f.input.focus();
_f.debug+="\nSet focus";
};
this.input_init_focus=function(){
_f.input.focus();
_f.cursor=msos.input_select.input_get_str_end(_f.input);
_f.debug+=_f.cursor.pos_debug+"\nInit focus: str -> "+_f.cursor.start+", end -> "+_f.cursor.end;
};
this.input_get_selection=function(){
var tmp=document.selection&&!window.opera?_f.input.value.replace(/\r/g,""):_f.input.value;
return tmp.substring(_f.cursor.start,_f.cursor.end);
};
this.input_set_cursor=function(_11,end){
var _13="\nSet Method: ";
if(!_11){
_11=_f.input.value.length;
end=_f.input.value.length;
}
if(_f.input.setSelectionRange){
if(window.KeyEvent){
_f.input.setSelectionRange(_11,_11+1);
var ev=document.createEvent("KeyEvents");
var cc=_f.input.value.charCodeAt(_11);
ev.initKeyEvent("keypress",true,true,null,false,false,false,false,0,cc);
_f.input.dispatchEvent(ev);
}
_f.input.setSelectionRange(_11,end);
_13+="setSelectionRange";
}else{
if(_f.input.createTextRange){
var _16=_f.input.createTextRange();
_16.collapse(true);
_16.moveStart("character",_11);
_16.moveEnd("character",end-_11);
_16.scrollIntoView(true);
_16.select();
_13+="move";
}
}
_13+="\nLast char code: "+_f.input.value.charCodeAt(_11-1);
_f.debug+="\nSet cursor: start -> "+_11+", end -> "+end+_13;
};
this.input_del_character=function(_17){
if(!_17){
_17=false;
}
var _18=_f.input.value;
var _19=_f.cursor.start;
var end=_f.cursor.end;
var tmp="";
if(_19==end){
var _1c=1;
var _1d=0;
if(window.opera){
if(_17){
_1d+=(_18.charCodeAt(_19+1)==10)?1:0;
}else{
_1d+=(_18.charCodeAt(_19-1)==10)?1:0;
}
}
if(_17){
_f.debug+="\nChar code at delete: "+_18.charCodeAt(_19+1);
}else{
_f.debug+="\nChar code at bkspace: "+_18.charCodeAt(_19-1);
}
_1c+=_1d;
_19=_17?_19:_19-_1c<0?0:_19-_1c;
end=_17?end+_1c:end;
}
tmp=document.selection&&!window.opera?_18.replace(/\r/g,""):_18;
_f.input.value=tmp.substring(0,_19)+tmp.substring(end,tmp.length);
_f.input_set_cursor(_19,_19);
};
this.input_ins_character=function(txt){
if(!txt){
return;
}
var _1f=_f.input.value;
var _20=txt.length;
var _21=0;
var _22=0;
var tmp="";
if(window.opera){
for(var i=0;i<txt.length;i++){
_21+=(txt.charCodeAt(i)==10)?1:0;
}
_20+=_21;
}
tmp=document.selection&&!window.opera?_1f.replace(/\r/g,""):_1f;
_f.input.value=tmp.substring(0,_f.cursor.start)+txt+tmp.substring(_f.cursor.end,tmp.length);
if(_f.cursor.end>_f.cursor.start){
_22=_f.cursor.start+_20;
}else{
_22=_f.cursor.end+_20;
}
_f.input_set_cursor(_22,_22);
};
};
msos.input_select.edit_insert_html=function(win,doc,ifr,_28){
var _29="edit_insert_html -> ";
var _2a=new msos.selection.generate_object(win,doc,ifr);
var _2b=_2a.get_selection();
var _2c=_2a.get_range(_2b);
if(!_2c){
return;
}
if(window.getSelection){
_29+="Moz & Opera way";
doc.execCommand("inserthtml",false,_28);
}else{
if(document.selection){
_29+="IE way";
if(_2c.pasteHTML){
if(_2b.type.toLowerCase()!="none"){
_2b.clear();
}
_2c.pasteHTML(_28);
}else{
doc.execCommand("inserthtml",false,_28);
}
}
}
_2a.set_focus();
console.debug(_29+", Completed!");
};
msos.input_select.set_bksp_del_select=function(win,doc,ifr,_30){
var _31="set_bksp_del_select -> ";
var _32=0;
var _33=false;
var tag="body";
var _35=new msos.selection.generate_object(win,doc,ifr);
_35.debug=false;
var _36=_35.selection_str_end();
if(typeof (_36)!="object"){
return;
}
if(_36.target&&_36.target.nodeName){
tag=_36.target.nodeName.toLowerCase();
}
if(/body|html|head|base/.test(tag)){
return;
}
if(typeof (_30)=="undefined"){
_30=false;
}
var _37=_36.start+_36.offset;
var end=_36.end+_36.offset;
if(_37!=end){
_33=true;
}else{
if(_30){
if(_37>0){
_37--;
_32=-1;
_33=true;
}
}else{
if(end<_36.max){
end++;
_32=1;
_33=true;
}
}
}
if(window.getSelection){
_31+="window.getSelection: ";
if(_33){
_36.range=_35.set_start_end(_36.target,_37,end);
_35.set_focus();
_36.select.removeAllRanges();
_36.select.addRange(_36.range);
_35.remove();
if(dojo.isOpera){
_36.range=_35.set_start_end(_36.target,_37,_37);
_35.set_focus();
_36.select.removeAllRanges();
_36.select.addRange(_36.range);
}
}
}else{
if(document.selection){
_31+="document.selection: ";
if(_33){
_36.range=_35.set_start_end(_36.target,_37,end);
_35.set_focus();
_36.range.select();
_35.remove();
}
}
}
if(_35.debug){
_35.selection_str_end();
}
console.debug(_31+"moved "+_32);
};
msos.input_select.insert_adj_html=function(_39,win,_3b){
if(_39.insertAdjacentHTML){
_39.insertAdjacentHTML("afterend",_3b);
}else{
var rng=win.document.createRange();
var _3d=rng.createContextualFragment(_3b);
if(_39.nextSibling){
_39.parentNode.insertBefore(_3d,_39.nextSibling);
}else{
_39.parentNode.appendChild(_3d);
}
}
};
msos.input_select.get_sel_parent_element=function(win,doc,ifr,_41){
if(!_41){
_41=false;
}
var _42=new msos.selection.generate_object(win,doc,ifr);
var _43=_42.getParentElement()||null;
if(_43){
if(!/html|head|base|body/i.test(_43.nodeName)){
return _43;
}else{
if((!/html|head|base/i.test(_43.nodeName)&&_41)){
return _43;
}else{
return null;
}
}
}else{
return null;
}
};
msos.input_select.scroll_test=function(_44,_45){
var pos={absLeft:0,absTop:0};
var _47=1;
var _48=1;
var h=_44.clientHeight;
var w=_44.clientWidth;
while(_45){
pos.absLeft+=_45.offsetLeft;
pos.absTop+=_45.offsetTop;
_45=_45.offsetParent;
}
var _4b=(pos.absTop>h);
var _4c=(pos.absLeft>w);
if(_4b||_4c){
return true;
}else{
return false;
}
};

